#pragma once
// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: paint_session.h
// Description: PaintSession Class
//      Author: Ziming Li
//     Created: 2022-05-03
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

#ifndef BLINKIT_PAINT_SESSION_H
#define BLINKIT_PAINT_SESSION_H

#include "blinkit/blink/renderer/platform/geometry/int_rect.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/zed/include/zed/mutex.hpp"

class SkBitmap;
class SkPaint;

namespace BlinKit {

class AnimationFrame;

class PaintSession
{
public:
    class Client;
    PaintSession(Client &client);
    ~PaintSession(void);

    void Initialize(HDC hdc, int cx, int cy);

    void BitBlt(HDC hdc, int x, int y, int cx, int cy);
    void FlushFrame(const SkBitmap &bitmap, const IntRect &dirtyRect, const SkPaint &paint);
    void SwapFrame(std::unique_ptr<AnimationFrame> &frame, const IntSize &size);

    static SkColor DefaultBackgroundColor(void);

    class Client {
    public:
        virtual void BitBlt(HDC hMemoryDC, const IntRect &rect) = 0;
    };
private:
    Client &m_client;
    zed::mutex m_paintLock;
    HDC m_memoryDC = nullptr;
    std::unique_ptr<AnimationFrame> m_currentFrame;
    HBITMAP m_oldBitmap = nullptr;
};

} // namespace BlinKit

#endif // BLINKIT_PAINT_SESSION_H
